@file:OptIn(ExperimentalMaterial3Api::class)

package com.example.cardiacmonitor.report

import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Download
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.cardiacmonitor.ui.theme.CardiacmonitorTheme

@Composable
fun ReportGeneratorScreen(navController: NavHostController) {
    Scaffold(
        topBar = {
            TopAppBar(
                title = { Text("报告生成系统") },
                navigationIcon = {
                    IconButton(onClick = { navController.popBackStack() }) {
                        Icon(Icons.Filled.ArrowBack, contentDescription = "返回")
                    }
                },
                actions = {
                    IconButton(onClick = { /* 导出报告 */ }) {
                        Icon(
                            imageVector = Icons.Filled.Download,
                            contentDescription = "导出报告"
                        )
                    }
                }
            )
        }
    ) { innerPadding ->
        Column(
            modifier = Modifier
                .padding(innerPadding)
                .fillMaxSize()
                .padding(all = 16.dp),
            verticalArrangement = Arrangement.spacedBy(16.dp)
        ) {
            // 患者信息摘要
            Card {
                Column(modifier = Modifier.padding(all = 16.dp)) {
                    Text("患者信息摘要", style = MaterialTheme.typography.titleLarge)
                    Spacer(modifier = Modifier.height(height = 8.dp))
                    Text("姓名: 张三")
                    Text("年龄: 45岁")
                    Text("性别: 男")
                    Text("ID: P20230045")
                }
            }

            // 心电图数据
            Card {
                Column(modifier = Modifier.padding(all = 16.dp)) {
                    Text("心电图数据", style = MaterialTheme.typography.titleLarge)
                    Spacer(modifier = Modifier.height(height = 8.dp))
                    Text("平均心率: 72 BPM")
                    Text("最高心率: 85 BPM")
                    Text("最低心率: 65 BPM")
                    Text("异常事件: 2次")
                }
            }

            // 诊断结论
            Card(
                colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant)
            ) {
                Column(modifier = Modifier.padding(all = 16.dp)) {
                    Text("诊断结论", style = MaterialTheme.typography.titleLarge)
                    Spacer(modifier = Modifier.height(height = 8.dp))
                    Text("窦性心律，偶发房性早搏，建议定期复查")
                }
            }

            // 生成报告按钮
            Button(
                onClick = { /* 生成报告逻辑 */ },
                modifier = Modifier.fillMaxWidth(),
                elevation = ButtonDefaults.buttonElevation(defaultElevation = 8.dp)
            ) {
                Text("生成完整报告")
            }
        }
    }
}

@Preview(showBackground = true)
@Composable
fun ReportGeneratorPreview() {
    CardiacmonitorTheme {
        ReportGeneratorScreen(rememberNavController())
    }
}